//
//  FANToolBar.m
//  Weibo - OC
//
//  Created by user on 16/4/21.
//  Copyright © 2016年 user. All rights reserved.
//

#import "FANToolBar.h"

//#warning 宏定义一定要放到 导入头文件的 上面, 会影响编译

//define this constant if you want to use Masonry without the 'mas_' prefix

#define MAS_SHORTHAND

//define this constant if you want to enable auto-boxing for default syntax

#define MAS_SHORTHAND_GLOBALS

#import <Masonry/Masonry.h>

@interface FANToolBar ()

//@property (nonatomic, strong) UIButton *retweetButton;
//
//@property (nonatomic, strong) UIButton *commitButton;
//
//@property (nonatomic, strong) UIButton *likeButton;

@end

@implementation FANToolBar

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI{

    UIButton *retweetButton = [self getButton:@"转发" and:@"timeline_icon_retweet"];
    UIButton *commitButton = [self getButton:@"评论" and:@"timeline_icon_comment"];
    UIButton *likeButton = [self getButton:@"赞" and:@"timeline_icon_unlike"];
    
    UIImageView *sp1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"timeline_card_bottom_line"]];
    
    UIImageView *sp2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"timeline_card_bottom_line"]];
    
    [self addSubview:retweetButton];
    [self addSubview:commitButton];
    [self addSubview:likeButton];
    [self addSubview:sp1];
    [self addSubview:sp2];
    
    [retweetButton makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.leading.bottom.equalTo(self);
        
        make.width.equalTo(commitButton);
        
    }];
    
    [commitButton makeConstraints:^(MASConstraintMaker *make) {
       
        make.leading.equalTo(retweetButton.trailing);
        
        make.top.bottom.equalTo(self);
        
        make.width.equalTo(likeButton);
        
    }];
    
    [likeButton makeConstraints:^(MASConstraintMaker *make) {
       
        make.leading.equalTo(commitButton.trailing);
        
        make.top.trailing.equalTo(self);
        
        make.width.equalTo(retweetButton);
        
    }];
    
    [sp1 makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.equalTo(retweetButton.trailing);
        
        make.centerY.equalTo(self.centerY);
        
    }];
    
    [sp2 makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(commitButton.trailing);
        
        make.centerY.equalTo(self.centerY);
        
    }];
    
    [self makeConstraints:^(MASConstraintMaker *make) {
       
        make.bottom.equalTo(retweetButton.bottom);
        
    }];
    
    

}

- (UIButton *)getButton:(NSString *)title and:(NSString *)imageName{
    
    UIButton *button = [[UIButton alloc] init];
    
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    
    [button setTitle:title forState:UIControlStateNormal];
    
    [button setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    
    [button setBackgroundImage:[UIImage imageNamed:@"timeline_card_bottom_background"] forState:UIControlStateNormal];
    
    button.titleLabel.font = [UIFont systemFontOfSize:15];
    
    [button setBackgroundImage:[UIImage imageNamed:@"timeline_card_bottom_background_highlighted"] forState:UIControlStateHighlighted];
    
    return button;
    
}

@end
